import request from './request'

// 用户登录
export const login = (data: { username: string; password: string }) => {
  return request({
    url: '/auth/login',
    method: 'POST',
    data
  })
}

// 用户登出
export const logout = () => {
  return request({
    url: '/auth/logout',
    method: 'POST'
  })
}

// 获取用户信息
export const getUserInfo = () => {
  return request({
    url: '/user/info',
    method: 'GET'
  })
}

// 获取用户列表
export const getUserList = (params?: { page: number; pageSize: number; keyword?: string }) => {
  return request({
    url: '/user/list',
    method: 'GET',
    params
  })
}

// 创建用户
export const createUser = (data: { username: string; password: string; email: string; role: string }) => {
  return request({
    url: '/user',
    method: 'POST',
    data
  })
}

// 更新用户
export const updateUser = (id: string, data: { username?: string; email?: string; role?: string }) => {
  return request({
    url: `/user/${id}`,
    method: 'PUT',
    data
  })
}

// 删除用户
export const deleteUser = (id: string) => {
  return request({
    url: `/user/${id}`,
    method: 'DELETE'
  })
}